package models

import (
	"database/sql"
	_ "github.com/mattn/go-sqlite3"
	"log"
)

type RefuseConnectFrom struct {
	RefuseTime string
	IP         string
}

func (m *RefuseConnectFrom) Save(db string) error {
	database, err := sql.Open("sqlite3", db)
	if err != nil {
		return err
	}
	stmt, err := database.Prepare("create table if not exists refuse_connect_from(refuseTime text, ip text)")
	if err != nil {
		log.Println(err)
	}
	result, err := stmt.Exec()
	if err != nil {
		log.Println(err)
	}
	log.Println(result)
	stmt, err = database.Prepare("insert into refuse_connect_from( refuseTime, ip) values(?,?)")
	if err != nil {
		return err
	}
	result, err = stmt.Exec(m.RefuseTime, m.IP)
	if err != nil {
		return err
	}
	log.Println(result)
	return nil
}

func (m *RefuseConnectFrom) TableName() string {
	return "refuse_connect_from"
}
